$(function () {

});

// 充值按钮
$(document).on('click', '.recharge-btn', function () {
    // 格式化输入
    // 判断输入值是否合法

    var regu = "^[0-9]{0,3}$",
        re = new RegExp(regu),
        s = $.trim($('.recharge-input').val());
    if (s == null || s == "") {
        // 输入不合法
        weui.alert('请输入充值金额');
        return false;
    }
    if (re.test(s)) {
        // 输入合法
        weui.dialog({
            title: '校淘支付',
            content: '￥' + s + '',
            className: 'custom-classname',
            buttons: [{
                label: '取消',
                type: 'default',
                onClick: function () {
                }
            }, {
                label: '支付',
                type: 'primary',
                onClick: function () {
                    var result = Model.user.recharge({
                        state: 0,
                        price: parseInt(s)
                    });
                    if (result.code = 1) {
                        weui.toast('充值成功', {
                            duration: 1500,
                            className: 'custom-classname',
                            callback: function () {

                                location.href = 'balance.html';
                            }
                        });
                    }

                }
            }]
        });

    } else {
        // 输入不合法
        weui.alert('输入金额不符合规范');
        return false;
    }
});